import React from 'react'
import {
  Form,
  Input,
  Button,
} from 'antd-mobile'
import axios from '../../api/index'
import { useNavigate } from 'react-router-dom'
function index() {
  const nav=useNavigate()
  const onFinish=(val)=>{
    console.log(val)
    axios.post('/login',val).then(res=>{
      console.log(res)
      localStorage.setItem('token',res.data.data.token)
      localStorage.setItem('userInfo',JSON.stringify(res.data.data.userInfo))
      nav('/')
    })
  }
  return (
    <div>
        <Form
        onFinish={onFinish}
        layout='horizontal'
        footer={
          <Button block type='submit' color='primary' size='large'>
            提交
          </Button>
        }
      > 
        <Form.Item
          name='username'
          label='账号'
          rules={[{ required: true, message: '账号不能为空' }]}
        >
          <Input  placeholder='请输入账号' />
        </Form.Item>
        <Form.Item
          name='password'
          label='密码'
          rules={[{ required: true, message: '密码不能为空' },
            {pattern:/^\w+.{6,12}$/,message:'密码格式不正确'}]}
        >
          <Input  placeholder='请输入密码' />
        </Form.Item>
        </Form>
    </div>
  )
}

export default index